package com.travel.mapper.user;

import com.travel.model.entity.interaction.Like;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
//点赞mapper 查询点赞 插入点赞 
@Mapper
@Repository("likeMapperMyBatis")
public interface LikeMapper {
    
    @Select("SELECT * FROM likes WHERE id = #{id}")
    Optional<Like> findById(@Param("id") Long id);
    
    @Select("SELECT * FROM likes WHERE user_id = #{userId} AND guide_id = #{guideId}")
    Optional<Like> findByUserIdAndGuideId(@Param("userId") Long userId, @Param("guideId") Long guideId);
    
    @Select("SELECT * FROM likes WHERE guide_id = #{guideId}")
    List<Like> findByGuideId(@Param("guideId") Long guideId);
    
    @Select("SELECT * FROM likes WHERE user_id = #{userId}")
    List<Like> findByUserId(@Param("userId") Long userId);
    
    @Insert("INSERT INTO likes (user_id, guide_id, created_time) " +
           "VALUES (#{user.id}, #{guide.id}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Like like);
    
    @Delete("DELETE FROM likes WHERE id = #{id}")
    int delete(Like like);
    
    @Delete("DELETE FROM likes WHERE user_id = #{userId} AND guide_id = #{guideId}")
    int deleteByUserIdAndGuideId(@Param("userId") Long userId, @Param("guideId") Long guideId);
    
    @Select("SELECT COUNT(*) FROM likes WHERE guide_id = #{guideId}")
    int countByGuideId(@Param("guideId") Long guideId);
} 